﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;

namespace tupleview
{
    public delegate void connect_handle(int id);
    public delegate int message_handle(int id, [MarshalAs(UnmanagedType.LPArray,SizeConst =1024)] byte[] data, int len);
    public delegate void error_handle(int id, int error_code);

    static class net_tuple
    {
        private const string dllname = "net_tuple";

        [DllImport(dllname)]
        public extern static void set_remote([MarshalAs(UnmanagedType.LPStr)] string ip,int port);
        
        [DllImport(dllname)]
        public extern static void bind_to(int port);

        [DllImport(dllname)]
        public extern static void set_on_client_connect(connect_handle handle);

        [DllImport(dllname)]
        public extern static void set_on_client_disconnect(connect_handle handle);

        [DllImport(dllname)]
        public extern static void set_on_server_connect(connect_handle handle);

        [DllImport(dllname)]
        public extern static void set_on_server_disconnect(connect_handle handle);

        [DllImport(dllname)]
        public extern static void set_on_client_message(message_handle handle);

        [DllImport(dllname)]
        public extern static void set_on_server_message(message_handle handle);

        [DllImport(dllname)]
        public extern static void set_on_client_error(error_handle handle);

        [DllImport(dllname)]
        public extern static void set_on_server_error(error_handle handle);

        [DllImport(dllname)]
        public extern static void send_to_client(int id, [MarshalAs(UnmanagedType.LPArray)] byte[] data,int len);

        [DllImport(dllname)]
        public extern static void send_to_server(int id, [MarshalAs(UnmanagedType.LPArray)] byte[] data, int len);
    }
}
